#!/usr/bin/env/ python3
from tqdm import tqdm
import time
import pikepdf


#定义一个密码字典
passwordfile = "passwordfile.txt"
#定义一个zip压缩包
pdf_files= "aaa.pdf"
#*打开*缩上面的压缩包
#zip_file = zipfile.ZipFile(zip_files)

word_len = len(list(open(passwordfile,"rb")))#定义密码字典的长度
print("密码字典共有：{}行".format(word_len))
with open(passwordfile,"rb") as file:
    for i in tqdm(file,total=word_len,unit="word"):
        time.sleep(0.01)#防止爆破过快
        pwd = str(i,'utf-8').replace('\n','').replace('\r','')#去除换行，编码为字符串str类型
        try:
            with pikepdf.open(pdf_files,password=pwd)as files:
                 pass
        except pikepdf._core.PasswordError as e:
               continue
        else:
             print("爆破出密码为{}".format(pwd))
             exit(0)
print("密码字典没有找到密码")
